const user = document.querySelector(".user");
const pwd = document.querySelector(".pwd");


let userRegular = /^[A-Za-z0-9_]{6,10}$/;
let pwdRegular1 = /[A-Z]{1,5}/;
let pwdRegular2 = /[a-z]{1,5}/;
let pwdRegular3 = /[0-9]{1,5}/;
let pwdRegular4 = /[!#$&.]{1,5}/;

const login_pwd =document.querySelector(".login_pwd");
const userPrompt = document.querySelector(".userprompt");
const pwdPrompt = document.querySelector(".pwdprompt");

function valication_user(){

    if (userRegular.test(user.value)) {
        user.style.border = "1px solid blue";
        userPrompt.innerText = '';

    }else {
        userPrompt.innerText = '用户名至少6个字符';
        user.style.border = "1px solid red";
    }
}
//用户名输入框
user.onfocus = function () {
    valication_user()
    user.oninput = function () {
        valication_user()
    }
}
//用户名输入完成判断用户名格式
user.onblur = function () {

}
//密码输入框
function valication_pwd(){
    console.log(pwd.value)

    if (pwd.value.length == 8){
        if(pwdRegular1.test(pwd.value)){
           if(pwdRegular2.test(pwd.value)){
               if(pwdRegular3.test(pwd.value)){
                   if(pwdRegular4.test(pwd.value)){
                       pwd.style.border = "1px solid blue";
                       pwdPrompt.innerText = '';
                   }
               }
           }
        }
    }else {
        pwdPrompt.innerText = '请输入8位数密码,必须有大小写字母、数字,特殊符号:#、&、.、$、!';
        pwd.style.border = "1px solid red";
    }
}
pwd.onfocus = function (){
    valication_pwd()
    pwd.oninput =function () {
        valication_pwd()
    }
}
//密码输入完成判断格式
pwd.onblur = function (){

}

const btn = document.querySelector(".btn");
const btnA = document.querySelector(".btn a");
const agreement = document.querySelector(".agreement>input");
const agrPrompt = document.querySelector(".agrPrompt");
//点击登录
btn.onclick = function () {
    if (user.style.border == "1px solid blue"){
        if (pwd.style.border == "1px solid blue") {

            if (agreement.checked) {
                user.value = '';
                location.href = '../index.html';
            } else {
                agrPrompt.innerText = '请勾选阅读并同意';
            };
        };
    };

};





